package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.PaasFormSubDataEntity;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.IndexTypeEnum;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 子表单处理用model
 * @author 魏荣杰
 * @date 2020/9/16 16:35
 * @since
 * @version
 */
public interface PaasFormSubDataModel {
    /**
     * Description: 查询并拼接子表单数据
     *
     * @param corpid
     * @param entitys
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2020/9/9 16:35
     * @since
     */
    void findSubEntity(String corpid, List<? extends PaasFormDataEntity> entitys, IndexTypeEnum indexTypeEnum);

    void findSubEntity4Invoice(List<? extends PaasFormDataEntity> entitys, String corpid);

    /**
     * Description: 将主数据data中的子表单数据移除并存放到 SubFormData 中
     * @param entity
     * @param indexTypeEnum
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2020/9/16 16:39
     * @since
     */
    void transferSubForm(PaasFormDataEntity entity, IndexTypeEnum indexTypeEnum);

    /**
     * 孤独子表单
     * @param entity
     * @param indexTypeEnum
     * @author xingxing.xiao
     * @date 2020/10/12 21:52
     */
    void transferSingleSubForm(PaasFormDataEntity entity, IndexTypeEnum indexTypeEnum);

    /**
     * Description: 单条数据的子表单数据插入数据库和es
     * @param entity
     * @param indexTypeEnum
     * @return java.lang.Integer
     * @throws
     * @author 魏荣杰
     * @date 2020/9/16 19:00
     * @since
     */
    Integer insertSubFormData(PaasFormDataEntity entity, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * 孤独子表单
     * @param entity
     * @param indexTypeEnum
     * @author xingxing.xiao
     * @date 2020/10/12 21:52
     */
    Integer insertSingleSubFormData(PaasFormDataEntity entity, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * Description: 多条数据的子表单数据插入数据库和es
     * @param entities
     * @param indexTypeEnum
     * @return java.lang.Integer
     * @throws
     * @author 魏荣杰
     * @date 2020/9/16 19:01
     * @since
     */
    Integer insertBatchSubFormData(List<? extends PaasFormDataEntity> entities, IndexTypeEnum indexTypeEnum) throws XbbException;
    /**
     * 孤独子表单
     * @param indexTypeEnum
     * @author xingxing.xiao
     * @date 2020/10/12 21:52
     */
    Integer insertBatchSingleSubFormData(List<? extends PaasFormDataEntity> entities, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * Description: 更新单条数据的子表单数据（数据库和es）
     * @param paasFormDataEntity
     * @param indexTypeEnum
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2020/9/16 19:02
     * @since
     * @return 1:更新或者新增，删除成功；0：操作子表单数据更新条数为0，没有新增和删除
     */
    Integer updateSubFormData(PaasFormDataEntity paasFormDataEntity, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * Description: 删除主表数据时，删除子表单数据，置del为2
     * @param dataId
     * @param corpid
     * @param indexTypeEnum
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2020/9/17 15:38
     * @since
     */
    void deleteByDataId(Long dataId, String corpid, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * Description:根据dataId批量删除
     * @param dataIds
     * @param corpid
     * @param indexTypeEnum
     * @param delEnum
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2020/9/23 09:52
     * @since
     */
    void deleteBatchByDataId(List<Long> dataIds, String corpid, IndexTypeEnum indexTypeEnum, DelEnum delEnum) throws XbbException;

    /**
     * Description:数据还原，目前只有一些特殊业务有
     * @param dataIds
     * @param corpid
     * @param indexTypeEnum
     * @return void
     * @throws
     * @author 魏荣杰
     * @date 2020/9/23 09:51
     * @since
     */
    void restoreBatch(List<Long> dataIds, String corpid, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * 根据Id和业务类型以及attr获取子表单数据
     * @param id 数据ID
     * @param corpid 公司ID
     * @param indexTypeEnum 业务类型
     * @param attr 字段名
     * @return List<? extends PaasFormSubDataEntity>
     * @throws XbbException error
     * @author zhouwq
     * @date 2020/9/28 15:47
     */
    List<? extends PaasFormSubDataEntity> getListByIdAndAttr(Long id, String corpid, IndexTypeEnum indexTypeEnum, String attr) throws XbbException;

    /**
     * 根据Id和业务类型以及attr获取子表单数据
     * @param id 数据ID
     * @param corpid 公司ID
     * @param indexTypeEnum 业务类型
     * @param attr 字段名
     * @param from
     * @param pageSize
     * @return List<? extends PaasFormSubDataEntity>
     * @throws XbbException error
     * @author zhouwq
     * @date 2020/9/28 15:47
     */
    List<? extends PaasFormSubDataEntity> getListByIdAndAttr(Long id, String corpid, IndexTypeEnum indexTypeEnum, String attr, Integer from, Integer pageSize) throws XbbException;

    Integer getCountByIdAndAttr(Long id, String corpid, IndexTypeEnum indexTypeEnum, String attr) throws XbbException;

    /**
     * 根据id查询子表单数据
     * @param idList
     * @param corpid
     * @param indexTypeEnum
     * @return List<? extends PaasFormSubDataEntity>
     * @throws XbbException
     */
    List<? extends PaasFormSubDataEntity> getByIdList(List<Long> idList, String corpid, IndexTypeEnum indexTypeEnum) throws XbbException;

    /**
     * 根据id查询子表单数据
     * @param idList
     * @param del
     * @param corpid
     * @param indexTypeEnum
     * @return List<? extends PaasFormSubDataEntity>
     * @throws XbbException
     */
    List<? extends PaasFormSubDataEntity> getByDataIdList(List<Long> idList, Integer del, String corpid, IndexTypeEnum indexTypeEnum) throws XbbException;
    /**
     * 根据indexTypeEnum获取子表单数据
     * @param map 查询参数
     * @param indexTypeEnum indexTypeEnum
     * @return List<? extends PaasFormSubDataEntity>
     */
    List<? extends PaasFormSubDataEntity> getSubDataList(Map<String, Object> map, IndexTypeEnum indexTypeEnum);

    void updateBatch(List<UpdateDataEntity> updateList, String corpid, IndexTypeEnum indexTypeEnum) throws XbbException;


    Integer updateBatch(List<? extends PaasFormSubDataEntity> list, IndexTypeEnum indexTypeEnum, String corpid) throws XbbException;

    /**
     * 返回
     * @param corpid 公司id
     * @see com.xbongbong.pro.enums.SaasMarkEnum
     * @param saasMark
     * @param businessType 业务类型
     * @param formId 表单id
     * @param parentIdList 主数据id
     * @param page 分页
     * @param pageSize
     * @param del
     * @return
     * @throws XbbException
     */
    Map<Long, JSONObject> getSubDataMap(String corpid, Integer saasMark, Integer businessType, Long formId, Collection<Long> parentIdList, Integer page, Integer pageSize, Integer del) throws XbbException;

    /**
     * 获取子表单最大id
     *
     * @param params
     * @return
     */
    Long getMaxId(Map<String, Object> params) throws XbbException;
}
